﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;
using System.Windows.Forms;

namespace Mail2Portfolio
{
    /// <summary>
    /// WebBrowserIE
    /// </summary>
    /// <remarks>
    /// http://stackoverflow.com/questions/4455607/watin-and-net-winforms-webbrowser-control-is-dialogwatcher-possible/
    /// var ie = new WebBrowserIE(webBrowser1);
    /// var thread = new Thread(() =>
    /// {
    ///     ie.GoTo("http://www.plus2net.com/javascript_tutorial/window-alert.php");
    ///     ie.Button(Find.ByValue("Click here to display alert message")).Click();
    /// });
    /// thread.SetApartmentState(ApartmentState.STA);
    /// thread.Start();
    /// </remarks>
    public class WebBrowserIE : IE
    {
        private IntPtr hwnd;

        public WebBrowserIE(WebBrowser webBrowserControl)
            : base(webBrowserControl.ActiveXInstance, false)
        {
            hwnd = webBrowserControl.FindForm().Handle;
            StartDialogWatcher();
        }

        public override IntPtr hWnd
        {
            get
            {
                return hwnd;
            }
        }

        protected override void Dispose(bool disposing)
        {
            hwnd = IntPtr.Zero;
            base.Dispose(disposing);
        }
    }
}
